﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace AlgoImpl
{
    [Serializable]
    public class Shift : IDataInTwoSideGraph
    {
        private string m_Name;
        private int m_MaxNumberOfWorkers;
        private List<Worker> m_Workers = new List<Worker>();
        

        private bool isWorkerExist(string worker)
        {
            bool isExist = false;
            foreach (Worker _worker in m_Workers)
            {
                if (_worker.Id.Equals(worker))
                {
                    isExist = true;
                    break;
                }
            }
            return isExist;
        }
        public Shift(string name, int numberOfShiftMax)
        {
            m_Name = name;
            m_MaxNumberOfWorkers = numberOfShiftMax;
        }
        public Shift() { }
        public void Clear()
        {
            m_Workers.Clear();
        }
        public bool IsFull()
        {
            return m_Workers.Count == m_MaxNumberOfWorkers;
        }
        public int MaxNumberOfShifts
        {
            get { return m_MaxNumberOfWorkers; }
            set { m_MaxNumberOfWorkers = value; }
        }

        public void AddWorker(string workerId)
        {
            if (!isWorkerExist(workerId))
            {
                m_Workers.Add(SharedData.Instance.GetWorkerById(workerId));
            }
        }
        public List<string> GetAllWorkersIds()
        {
            List<string> workersIds = new List<string>();
            foreach (Worker worker in m_Workers)
            {
                workersIds.Add(worker.Id);
            }
            return workersIds;
        }
        public string Name
        {
            get
            {
                return m_Name;
            }

        }
        public string Id { get; set; }

        //public List<Worker> Workers 
        //{
        //    get { return m_Workers; }
        //    set { m_Workers = value; } 
        //}
        public int GetNumberOfFreePlaces()
        {
            return m_MaxNumberOfWorkers - m_Workers.Count;
        }

        public override bool Equals(object obj)
        {
            bool isEqual = false;
            if (typeof(Shift) == obj.GetType())
            {
                if ((obj as Shift).Id.Equals(Id))
                {
                    isEqual = true;
                }
            }
            return isEqual;
        }
        public override string ToString()
        {
            string toReturn = string.Empty;
            string workersAsString = string.Empty;
            foreach (Worker workerId in m_Workers)
            {
                workersAsString += workerId.ToString();
            }
            if (string.IsNullOrEmpty(workersAsString)) { workersAsString = "No workers"; }
            toReturn = string.Format("Id: {0} Name: {1}, MaxnumOfWorkers: {2} , CurrNumOfWorkers: {3}, {4}",
                Id, m_Name, m_MaxNumberOfWorkers, m_Workers.Count, workersAsString);
            return toReturn;
        }
    }
}

